import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:personinfo/model/home/SearchCarModel.dart';
import 'package:personinfo/page/home/ImagePickerDemo.dart';
import 'package:personinfo/widgets/common/IconText.dart';

import '../states/appController.dart';
import '../widgets/common/CommonWidget.dart';
import '../widgets/common/LineNav.dart';
import '../widgets/common/MiniTitleNav.dart';
import '../widgets/common/carNav.dart';
import '../widgets/common/messgeNav.dart';



class Home extends StatefulWidget{
  const Home({super.key});

  @override
  State<StatefulWidget> createState() => _MyHome();
}


class _MyHome extends State<Home>{
  //选择
  Future<int?> _showModalBottomSheet() {
    return showModalBottomSheet<int>(
      context: context,
      builder: (BuildContext context) {
        return ListView.builder(
          itemCount: 30,
          itemBuilder: (BuildContext context, int index) {
            return ListTile(
              title: Text("$index"),
              onTap: () => Navigator.of(context).pop(index),
            );
          },
        );
      },
    );
  }

  //拍照
  _photo(){
    return showModalBottomSheet(
        context: context,
        builder:(BuildContext context){
          return const ImagePickerDemo();
        }
    );
  }

  @override
  Widget build(BuildContext context) {

    // TODO: implement build
    return GetBuilder<AppController>(
      init: AppController(),
      builder: (controller){
        return Scaffold(
          backgroundColor: Theme.of(context).colorScheme.onPrimary,
          appBar: commonWidget.appBar(
              title: const Text("首页"),

              leading: Builder(builder: (context){
                return IconButton(
                  icon: const Icon(Icons.menu),
                  onPressed: () {
                    print("新页面");
                  },
                );
              }
            )
          ),
          body: SingleChildScrollView(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Image.asset('assets/images/banner.jpg'),
                const SizedBox(height: 5,),
                const MiniTitleNav(title: "产品服务",),
                const SizedBox(height: 10,),
                Flex(
                  direction: Axis.horizontal,
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children:  [
                    IconText(icon: Icons.airplay_sharp, text: "发布",iconColors: const Color.fromRGBO(166, 1, 227, 1),iconFontSize: 26,onTap: (){
                      Navigator.pushNamed(context, "/publishSearchCar",arguments: SearchCarModel());
                    }),
                    IconText(icon: Icons.search_off_rounded, text: "我的寻车",iconColors: Color.fromRGBO(55, 192, 0, 1),iconFontSize: 26,
                      onTap: (){
                        Navigator.pushNamed(context, "/mySearchCar",arguments: {"index": 0, "subIndex": 0});
                      },
                    ),
                    IconText(icon: Icons.file_copy, text: "待支付订单",iconColors: Color.fromRGBO(233, 1, 1, 1),iconFontSize: 26, onTap: (){
                      Navigator.pushNamed(context, "/orderList", arguments: {"index": 2});
                    },),

                    IconText(icon: Icons.file_open, text: "订单管理",iconColors: const Color.fromRGBO(2, 196, 100, 1),iconFontSize: 26,onTap: (){
                      Navigator.pushNamed(context, "/orderList", arguments: {"index": 0});
                    },),

                    const IconText(icon: Icons.event_busy, text: "拼团",iconColors: Color.fromRGBO(0, 177, 254, 1),iconFontSize: 26,),
                  ],
                ),
                const SizedBox(height: 10,),
                MiniTitleNav(title: "我的消息",showMore: true,onTap: (){
                  Navigator.pushNamed(context, "/messageNotify",arguments: {"index": 0});
                },),


                messgeNav( title: '新的业务消息',tipNum: '2',onTap: ()=>Navigator.pushNamed(context, "/messageNotify",arguments: {"index": 1})),
                messgeNav( title: '新的系统消息',tipNum: '',onTap: ()=>Navigator.pushNamed(context, "/messageNotify",arguments: {"index": 2}),),

                const SizedBox(height: 10,),
                LineNav().heightLine(),
                const SizedBox(height: 5,),
                const MiniTitleNav(title: "最新车源"),

                carNav.carItem(
                  carIcon: Icons.ac_unit_sharp,
                  carName: "比亚迪",
                  carPrice: "20",
                  carDesc: "比亚迪车系列12121比亚迪车系列12121比亚迪车系列12121比亚迪车系列12121",
                  onTap: (){
                    Navigator.pushNamed(context, "/carResourceDetail",arguments: {"carName": "比亚迪"});
                  }
                ),
                carNav.carItem(
                    carIcon: Icons.add_a_photo_outlined,
                    carName: "路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎路虎",
                    carPrice: "50",
                    carDesc: "比亚迪车系列12121比亚迪车系列12121比亚迪车系列12121比亚迪车系列12121比亚迪车系列12121",
                    onTap: (){
                      Navigator.pushNamed(context, "/carResourceDetail",arguments: {"carName": "路虎路"});
                    }
                ),
                carNav.carItem(
                  carIcon: Icons.abc,
                  carName: "福特-福克斯",
                  carPrice: "30",
                  carDesc: "这是福克斯车系这是福克斯车系这是福克斯车系这是福克斯车系这是福克斯车系",
                    onTap: (){
                      Navigator.pushNamed(context, "/carResourceDetail",arguments: {"carName": "福特-福克斯"});
                    }
                ),
                SizedBox(height: 10,)

              ],
            ),
          )

      );
    },);
  }
}



